package com.ruoyi.web.controller.english;

import java.util.List;


import com.ruoyi.english.domain.EnWord;
import com.ruoyi.english.service.IEnWordService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 单词Controller
 * 
 * @author ruoyi
 * @date 2021-12-25
 */
@RestController
@RequestMapping("/english/word")
public class EnWordController extends BaseController
{
    @Autowired
    private IEnWordService enWordService;

    /**
     * 查询单词列表
     */
    @PreAuthorize("@ss.hasPermi('english:word:list')")
    @GetMapping("/list")
    public TableDataInfo list(EnWord enWord)
    {
        startPage();
        List<EnWord> list = enWordService.selectEnWordList(enWord);
        return getDataTable(list);
    }

    /**
     * 导出单词列表
     */
    @PreAuthorize("@ss.hasPermi('english:word:export')")
    @Log(title = "单词", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(EnWord enWord)
    {
        List<EnWord> list = enWordService.selectEnWordList(enWord);
        ExcelUtil<EnWord> util = new ExcelUtil<EnWord>(EnWord.class);
        return util.exportExcel(list, "单词数据");
    }

    /**
     * 获取单词详细信息
     */
    @PreAuthorize("@ss.hasPermi('english:word:query')")
    @GetMapping(value = "/{wordId}")
    public AjaxResult getInfo(@PathVariable("wordId") Long wordId)
    {
        return AjaxResult.success(enWordService.selectEnWordByWordId(wordId));
    }

    /**
     * 新增单词
     */
    @PreAuthorize("@ss.hasPermi('english:word:add')")
    @Log(title = "单词", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EnWord enWord)
    {
        return toAjax(enWordService.insertEnWord(enWord));
    }

    /**
     * 修改单词
     */
    @PreAuthorize("@ss.hasPermi('english:word:edit')")
    @Log(title = "单词", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EnWord enWord)
    {
        return toAjax(enWordService.updateEnWord(enWord));
    }

    /**
     * 删除单词
     */
    @PreAuthorize("@ss.hasPermi('english:word:remove')")
    @Log(title = "单词", businessType = BusinessType.DELETE)
	@DeleteMapping("/{wordIds}")
    public AjaxResult remove(@PathVariable Long[] wordIds)
    {
        return toAjax(enWordService.deleteEnWordByWordIds(wordIds));
    }
}
